import { resolve } from 'path'
import { defineConfig, externalizeDepsPlugin } from 'electron-vite'
import optimizer from 'vite-plugin-optimizer'
import vue from '@vitejs/plugin-vue'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'

export default defineConfig({
  main: {
    plugins: [externalizeDepsPlugin(),
      ]
  },
  preload: {
    plugins: [
      externalizeDepsPlugin(),
      ]
  },
  renderer: {
    resolve: {
      alias: {
        '@renderer': resolve('src/renderer/src')
      }
    },
    plugins: [vue(),
      optimizer({ // 配置使用ipcRenderer的时候会出现path.join undefined的问题
        electron: `const { ipcRenderer } = require('electron'); export { ipcRenderer };`
      }),
      AutoImport({ // elementui按需引入
        resolvers: [ElementPlusResolver()],
      }),
      Components({ // elementui按需引入
        resolvers: [ElementPlusResolver()],
      }),
    ]
  },
  
})
